package com.bawei.week.visit

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import androidx.core.view.isVisible
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bawei.lib_base.mvvm.BaseActivity
import com.bawei.week.R
import com.bawei.week.databinding.ActivityVisitDetailBinding
import dagger.hilt.android.AndroidEntryPoint

@Route(path = "/app/VisitDetailActivity")
@AndroidEntryPoint
class VisitDetailActivity : BaseActivity<ActivityVisitDetailBinding,VisitViewModel>(){
    @Autowired
    @JvmField
    var visitId = 0
    var status = "已通过"
    override fun initView() {
        ARouter.getInstance().inject(this)

        vm.getVisitDetail(visitId)

        binding.visitDetailRg.setOnCheckedChangeListener { radioGroup, checkId ->
            if (checkId == R.id.visit_detail_yes){
                status = "已通过"
            }else{
                status = "驳回"
            }
        }

        binding.visitDetailBtn.setOnClickListener {
            if (status == "已通过"){
                vm.getVisitReject(visitId)
            }else{
                vm.getVisitApprove(visitId)
            }
        }
    }

    override fun initData() {
        vm.visitDetailSuc.observe(this){
            binding.bean = it

            val split = it.appointmentTime.split(Regex("[ ,]"))
            binding.visitDetailStart.text = "开始时间:" + split[0] + " " + split[1]
            if (split.size == 3){
                binding.visitDetailEnd.text = "结束时间:" + split[0] + " " + split[2]
            }

            if (it.visitStatus == "已通过"){
                binding.visitDetailRg.visibility == View.GONE
                binding.visitDetailBtn.text = "立即缴费"
            }else{
                binding.visitDetailRg.visibility == View.GONE
            }
        }
    }
}